package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.manager.wingroom.CrossWingRoomMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/3/25 14:54
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_SYNC_CHANGE_EVENT_TO_CROSS, desc = "同步变动的事件")
public class CrossSyncChangeEventCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.SyncCrossAllEventStatusMsg msg = WingRoomProto.SyncCrossAllEventStatusMsg.parseFrom(packet.getBytes());
        CrossWingRoomMgr.putEventData(msg);

        //v4.8
        long serverId = CrossAgentLinkedControl.getLinkedClient(ctx).getServerId();
        List<Long> userList = new ArrayList<>();
        for (WingRoomProto.CrossEventStatusMsg eventStatusMsg : msg.getMsgList()) {
            userList.add(eventStatusMsg.getUserId());
        }
        CrossWingRoomMgr.markUserEventDataChange(serverId, userList);

    }
}
